import requests


class SendMethod:
    @staticmethod
    def sendmethod(method, url, params=None, data=None, json=None, headers=None):
        if method == "get":
            response = requests.get(url=url, params=params, headers=headers)
        elif method == "post":
            if data is None and json is None:
                response = requests.post(url=url, headers=headers)
            elif data is not None and json is  None:
                response = requests.post(url=url, data=data, headers=headers)
            else:
                response = requests.post(url=url, json=json, headers=headers)
        else:
            response = None
            print("请求方式错误")
        result = {}
        if response is not None:
            result['status_code'] = response.status_code
            result["headers"] = response.headers
            result["body"] = response.json()
            result["response_time"] = int(response.elapsed.microseconds / 1000)
            return result
        else:
            return response


if __name__ == '__main__':
    url = "http://47.108.206.100:8080/admin/login"
    method = "post"
    body = {
        "username": "admin",
        "password": "macro123"
    }
    print(SendMethod().sendmethod(method=method, url=url, data=body))
